/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package easybooking.clients.gui.report;

import easybooking.data.Airline;
import java.rmi.RemoteException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Tim Schröder
 */
public class RCAirlineTableModel extends AbstractTableModel {

    private Vector<Airline> airlines;
    private static final int ID_INDEX = 0;
    private static final int NAME_INDEX = 1;
    private static final int INITIALS_INDEX = 2;
    private static final int OBJECT = 3;
    private String[] columnNames = {"ID", "Name", "Initials"};

    /**
     * constructor for the RCAirlineTableModel class
     * @param airl
     */
    public RCAirlineTableModel(Vector<Airline> airl) {
        airlines = airl;
    }

    /**
     * get the number of rows the table needs
     * @return the number of airline objects in the airlines Vector
     */
    public int getRowCount() {
        return airlines.size();
    }

    /**
     * get the number of columns
     * @return the number of the column Names
     */
    public int getColumnCount() {
        return columnNames.length;

    }

    @Override
    /**
     * get the name of a column
     * @param col is the number of the column which name is wanted
     * @return the name of a column
     */
    public String getColumnName(int col) {
        return columnNames[col];
    }

    /**
     * prepares the airline data for the table
     * @param rowIndex the row in which the data get insert
     * @param columnIndex the column in which the data get insert
     * @return the prepared object
     */
    public Object getValueAt(int rowIndex, int columnIndex) {
        try {
            Airline airl = (Airline) airlines.get(rowIndex);
            switch (columnIndex) {
                case ID_INDEX:
                    return airl.getAirlineId();
                case NAME_INDEX:
                    return airl.getName();
                case INITIALS_INDEX:
                    return airl.getInitials();
                case OBJECT:
                    return airl;
                default:
                    return new Object();
            }
        } catch (RemoteException ex) {
            Logger.getLogger(RCAirlineTableModel.class.getName()).log(Level.SEVERE, null, ex);
            return new Object();
        }
    }
}

